/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import model.ObjetoTablaEnvios;
import model.ObjetoTablaPaquetesRegistrados;
import model.Paquete;
import util.EnviarCorreo;

/**
 *
 * @author Enrique
 */
public class ListaIdsPaquetes extends javax.swing.JFrame {

    /**
     * Creates new form ListaIdsPaquetes
     */
    
    private Vector columnasTablaPaquetes; 
    private DefaultTableModel modeloTablaPaquetes;    
    private List<ObjetoTablaPaquetesRegistrados> listaFilasTablaPaquetes;  
    private List<Paquete> listaPaquetes;
    
    // constructor por defecto
    public ListaIdsPaquetes() {
        initComponents();
    }
    
    // constructor con lista de paquetes
    public ListaIdsPaquetes(List<Paquete> listaPaquetes) {
        initComponents();
        this.listaPaquetes=listaPaquetes;
        EnviarCorreo correo = new EnviarCorreo();
        
        //Envio Correo al Cliente
        correo.enviarCorreoCliente(listaPaquetes);
        
        // inicializo la tabla
        columnasTablaPaquetes = new Vector();
        columnasTablaPaquetes.add("Id");
        columnasTablaPaquetes.add("Ciudad Origen");
        columnasTablaPaquetes.add("Ciudad Destino");
        modeloTablaPaquetes = new DefaultTableModel(this.columnasTablaPaquetes, 0) {
            public boolean isCellEditable(int row, int column) { // para que no se pueda editar directamente la tabla
                return false;
            }
        };
        this.tblResult.setModel(modeloTablaPaquetes);
        this.tblResult.setCellSelectionEnabled(false); // para que no se puedan seleccionar celdas individuales
        this.tblResult.setRowSelectionAllowed(true);   // para que se seleccione la fila entera
        
        // meto los paquetes a la tabla
        for (int i = 0; i < listaPaquetes.size(); i++) {
            Object[] o = new Object[3];
            o[0] = listaPaquetes.get(i).getIdPaquete();
            o[1] = listaPaquetes.get(i).getCiudadByIdCiudadOrigen().getCiudad();
            o[2] = listaPaquetes.get(i).getCiudadByIdCiudadDestino().getCiudad();
            modeloTablaPaquetes.addRow(o);
            
            //Enviar correo al receptor del paquete
            correo.enviarCorreoRecepcion(listaPaquetes.get(i));
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblResult = new javax.swing.JTable();
        btnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Paquetes Registrados");
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jLabel1.setText("Se registraron los siguientes paquetes:");
        jLabel1.setToolTipText("");

        tblResult.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jScrollPane1.setViewportView(tblResult);

        btnAceptar.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        btnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/aceptar.png"))); // NOI18N
        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(137, 137, 137)
                .addComponent(btnAceptar))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnAceptar))
        );

        setSize(new java.awt.Dimension(398, 503));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    // click a boton Aceptar
    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
       this.dispose();
        new Menu().setVisible(true); 
    }//GEN-LAST:event_btnAceptarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ListaIdsPaquetes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ListaIdsPaquetes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ListaIdsPaquetes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ListaIdsPaquetes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ListaIdsPaquetes().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblResult;
    // End of variables declaration//GEN-END:variables
}
